package cn.ruituo.adv5.exe.sp;

import java.io.*;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        final String SP_NAME="supermarket.txt";
        //有则读之，无则new之
        ObjectInputStream ois=null;
        Supermarket su=null;
        Scanner sc=new Scanner(System.in);
        try {
            ois=new ObjectInputStream(new FileInputStream(SP_NAME));
            su= (Supermarket) ois.readObject();
            ois.close();
        } catch (Exception e) {
            // e.printStackTrace();
            System.out.println("超市不存在");
            System.out.println("新店开张，起个名字:");
            su=new Supermarket(sc.next());
        }
        int choice=0;
        while(true){
            System.out.println("1:开卡，2：查看会员，9：退出");
            choice=sc.nextInt();
            if(choice==1){
                System.out.println("请输入会员姓名：");
                String name=sc.next();
                System.out.println("请输入会员卡号：");
                long id=sc.nextLong();
                System.out.println("请输入会员积分：");
                int score=sc.nextInt();
                su.openCard(name,id,score);
            }else if(choice==2){
                su.search();
            }else if(choice==9){
                ObjectOutputStream oos=null;
                try {
                    oos=new ObjectOutputStream(new FileOutputStream(SP_NAME));
                    oos.writeObject(su);
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            }
        }
    }
}
